package nothing.dao.hibernate;

import nothing.Util;
import nothing.model.Recipe;
import nothing.dao.RecipeDao;
import org.appfuse.dao.hibernate.GenericDaoHibernate;

import java.util.ArrayList;
import java.util.List;

public class RecipeDaoHibernate extends GenericDaoHibernate<Recipe, Long> implements RecipeDao {

    public RecipeDaoHibernate() {
        super(Recipe.class);
    }

    @SuppressWarnings("unchecked")
    public List<Recipe> findByName(String name) {
        return getHibernateTemplate().find("from Recipe where name=?", name);
    }

    @SuppressWarnings("unchecked")
    public List<Recipe> findByType(String name) {
        List<Object[]> mess = getHibernateTemplate().find("from Recipe r, RecipeType rt, Type t where rt.recipe = r and rt.type = t and t.name=?", name);
        final List recipe = new ArrayList();
        recipe.addAll(Util.toList(mess,0));
        return recipe;
    }


}
